from rest_framework import serializers

from managesys.models import Student, Grade, College



class GradeSerilizer(serializers.ModelSerializer):
    """班级序列化器"""
    college = serializers.SerializerMethodField

    @staticmethod
    def get_college(grade):
        return CollegeSerilizer(grade.college)


    class Meta:
        model = Grade
        fields = '__all__'

class StudentSimpleSerilizer(serializers.ModelSerializer):
    """学生信息简单序列化器"""
    grade = serializers.SerializerMethodField

    @staticmethod
    def get_grade(student):
        return GradeSerilizer(student.grade)

    class Meta:
        model = Student
        exclude = ('stuno',)

class CollegeSerilizer(serializers.ModelSerializer):
    """学院序列化器"""

    class Meta:
        model = College
        fields = '__all__'